home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / bezobj / bezier_surface.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-09  |  1.3 KB  |  76 lines

  1. #include "..\..\lib\Fly3D.h"
  2. #include "bezobj.h"
  3.  
  4. void bezier_surface::init()
  5. {
  6.     if (patch&&source)
  7.     {
  8.     pos=patch->pivot;
  9.     patch->build_surface();
  10.     if (objmesh)
  11.         delete objmesh;
  12.     objmesh=patch->build_mesh();
  13.     }
  14. }
  15.  
  16. bsp_object *bezier_surface::clone()
  17. {
  18.     bezier_surface *tmp=new bezier_surface;
  19.     *tmp=*this;
  20.     tmp->source=this;
  21.     return tmp;
  22. }
  23.  
  24. int bezier_surface::get_custom_param_desc(int i,param_desc *pd)
  25. {
  26.     if (pd!=0)
  27.     switch(i)
  28.     {
  29.     case 0:
  30.         pd->type='h';
  31.         pd->data=&patch;
  32.         strcpy(pd->name,"patch");
  33.         break;
  34.     }
  35.     return 1;
  36. }
  37.  
  38. void bezier_surface::draw()
  39. {
  40.     if (patch)
  41.     {
  42.         glPushMatrix();
  43.         glTranslatef(pos.x,pos.y,pos.z);
  44.         glMultMatrixf((float *)&mat);
  45.  
  46.         int i=((int)(flyengine->cam->pos-pos).length());
  47.         int d=(int)flyengine->viewmaxdist;
  48.  
  49.         i-=(d>>1);
  50.         if (i<0)
  51.             patch->draw(0);
  52.         else 
  53.         {
  54.             i-=(d>>2);
  55.             if (i<0)
  56.                 patch->draw(1);
  57.             else
  58.                 patch->draw(2);
  59.         }
  60.  
  61.         glPopMatrix();
  62.     }
  63. }
  64.  
  65. int bezier_surface::message(vector& p,float rad,int msg,int param,void *data)
  66. {
  67.     if (msg==FLYOBJM_ILLUM && (flyengine->mapmode&MAPPING_LIGHTMAP))
  68.         patch->illuminate((p-pos)*mat_t,rad,*((vector *)data),param);
  69.     else 
  70.     if (msg==FLYOBJM_CHANGEPARAM)
  71.         if (param>=0 || 
  72.             ((param_desc *)data)->data==&flyengine->curveerr)
  73.             init();
  74.     return 0;
  75. }
  76.